<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教材版本管理 - 带Mock数据</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#2563eb',
                        success: '#10b981',
                        warning: '#f59e0b',
                        danger: '#ef4444',
                    }
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .transition-smooth {
                transition: all 0.3s ease;
            }
        }
    </style>
</head>
<body class="bg-gray-50 font-sans">
    <div class="min-h-screen flex flex-col">
        <!-- 顶部导航 -->
        <header class="bg-white shadow-sm">
            <div class="container mx-auto px-4 py-3 flex items-center justify-between">
                <div class="flex items-center gap-2">
                    <i class="fa fa-graduation-cap text-primary text-2xl"></i>
                    <h1 class="text-xl font-bold">智慧教育题库系统</h1>
                </div>
                <div class="flex items-center gap-4">
                    <button class="text-gray-500 hover:text-primary transition-smooth">
                        <i class="fa fa-bell-o"></i>
                    </button>
                    <div class="flex items-center gap-2">
                        <img src="https://picsum.photos/id/1001/40/40" alt="用户头像" class="w-8 h-8 rounded-full">
                        <span class="text-sm font-medium">李老师</span>
                    </div>
                </div>
            </div>
        </header>

        <!-- 主内容区 -->
        <main class="flex-1 container mx-auto px-4 py-6">
            <!-- 页面标题 -->
            <div class="mb-6">
                <h2 class="text-2xl font-bold text-gray-800">教材版本管理</h2>
                <p class="text-gray-500 mt-1">管理各版本教材信息，支持多版本并行与更新</p>
            </div>

            <!-- 筛选区 -->
            <div class="bg-white rounded-lg shadow-md p-4 mb-6">
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">出版社</label>
                        <select id="publisherFilter" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-primary/50 focus:border-primary">
                            <option value="">全部出版社</option>
                            <option value="人民教育出版社">人民教育出版社</option>
                            <option value="江苏教育出版社">江苏教育出版社</option>
                            <option value="北京师范大学出版社">北京师范大学出版社</option>
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">学段</label>
                        <select id="stageFilter" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-primary/50 focus:border-primary">
                            <option value="">全部学段</option>
                            <option value="小学">小学</option>
                            <option value="初中">初中</option>
                            <option value="高中">高中</option>
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
                        <select id="statusFilter" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-primary/50 focus:border-primary">
                            <option value="">全部状态</option>
                            <option value="现行">现行</option>
                            <option value="过渡">过渡</option>
                            <option value="停用">停用</option>
                        </select>
                    </div>
                    <div class="flex items-end">
                        <button id="searchBtn" class="w-full px-4 py-2 bg-primary text-white rounded-md hover:bg-primary/90 transition-smooth">
                            <i class="fa fa-search mr-1"></i> 搜索
                        </button>
                    </div>
                </div>
            </div>

            <!-- 教材版本列表 -->
            <div class="bg-white rounded-lg shadow-md overflow-hidden">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">序号</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">教材名称</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">出版社</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">适用学段</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">适用年级</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">出版年份</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">状态</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">章节数</th>
                            <th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">操作</th>
                        </tr>
                    </thead>
                    <tbody id="textbookList" class="bg-white divide-y divide-gray-200">
                        <!-- Mock数据将通过JS动态渲染 -->
                    </tbody>
                </table>

                <!-- 分页 -->
                <div class="px-6 py-3 flex items-center justify-between border-t border-gray-200">
                    <div class="text-sm text-gray-700">
                        显示 <span id="showingRange">1-10</span> 条，共 <span id="totalCount">24</span> 条
                    </div>
                    <div class="flex gap-2">
                        <button class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-50 transition-smooth">上一页</button>
                        <button class="px-3 py-1 bg-primary text-white rounded">1</button>
                        <button class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-50 transition-smooth">2</button>
                        <button class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-50 transition-smooth">3</button>
                        <button class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-50 transition-smooth">下一页</button>
                    </div>
                </div>
            </div>
        </main>

        <!-- 新增按钮 -->
        <button id="addBtn" class="fixed right-6 bottom-6 w-14 h-14 bg-primary text-white rounded-full shadow-lg flex items-center justify-center text-xl hover:bg-primary/90 transition-smooth">
            <i class="fa fa-plus"></i>
        </button>

        <!-- 页脚 -->
        <footer class="bg-white border-t border-gray-200 py-4 mt-6">
            <div class="container mx-auto px-4 text-center text-sm text-gray-500">
                © 2025 智慧教育题库系统 - 版权所有
            </div>
        </footer>
    </div>

    <!-- 新增教材版本弹窗 -->
    <div id="addModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg w-full max-w-md mx-4 transform transition-smooth scale-95 opacity-0" id="modalPanel">
            <div class="px-6 py-4 border-b border-gray-200 flex justify-between items-center">
                <h3 class="text-lg font-semibold">新增教材版本</h3>
                <button id="closeModal" class="text-gray-400 hover:text-gray-600">
                    <i class="fa fa-times"></i>
                </button>
            </div>
            <div class="px-6 py-5">
                <form id="addForm">
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">教材名称 <span class="text-danger">*</span></label>
                        <input type="text" class="w-full px-3 py-2 border border-gray-300 rounded-md" placeholder="例如：数学必修一">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">出版社 <span class="text-danger">*</span></label>
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-md">
                            <option value="">请选择出版社</option>
                            <option value="人民教育出版社">人民教育出版社</option>
                            <option value="江苏教育出版社">江苏教育出版社</option>
                            <option value="北京师范大学出版社">北京师范大学出版社</option>
                        </select>
                    </div>
                    <div class="grid grid-cols-2 gap-4 mb-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">适用学段 <span class="text-danger">*</span></label>
                            <select class="w-full px-3 py-2 border border-gray-300 rounded-md">
                                <option value="">请选择</option>
                                <option value="小学">小学</option>
                                <option value="初中">初中</option>
                                <option value="高中">高中</option>
                            </select>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">适用年级 <span class="text-danger">*</span></label>
                            <input type="text" class="w-full px-3 py-2 border border-gray-300 rounded-md" placeholder="例如：高一">
                        </div>
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">出版年份 <span class="text-danger">*</span></label>
                        <input type="number" class="w-full px-3 py-2 border border-gray-300 rounded-md" placeholder="例如：2023">
                    </div>
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">章节结构导入</label>
                        <div class="border-2 border-dashed border-gray-300 rounded-md p-6 text-center">
                            <i class="fa fa-file-excel-o text-gray-400 text-3xl mb-2"></i>
                            <p class="text-sm text-gray-500">拖拽Excel文件至此处或 <span class="text-primary cursor-pointer">点击上传</span></p>
                            <p class="text-xs text-gray-400 mt-1">支持.xlsx格式，模板下载</p>
                        </div>
                    </div>
                </form>
            </div>
            <div class="px-6 py-4 bg-gray-50 rounded-b-lg flex justify-end gap-3">
                <button id="cancelBtn" class="px-4 py-2 border border-gray-300 rounded-md hover:bg-gray-50 transition-smooth">取消</button>
                <button class="px-4 py-2 bg-primary text-white rounded-md hover:bg-primary/90 transition-smooth">保存</button>
            </div>
        </div>
    </div>

    <script>
        // Mock数据
        const textbookData = [
            { id: 1, name: '数学必修一', publisher: '人民教育出版社', stage: '高中', grade: '高一', year: 2023, status: '现行', chapters: 5 },
            { id: 2, name: '数学必修二', publisher: '人民教育出版社', stage: '高中', grade: '高一', year: 2023, status: '现行', chapters: 4 },
            { id: 3, name: '数学必修一', publisher: '江苏教育出版社', stage: '高中', grade: '高一', year: 2022, status: '现行', chapters: 5 },
            { id: 4, name: '数学必修二', publisher: '江苏教育出版社', stage: '高中', grade: '高一', year: 2022, status: '现行', chapters: 6 },
            { id: 5, name: '数学必修一', publisher: '北京师范大学出版社', stage: '高中', grade: '高一', year: 2023, status: '现行', chapters: 5 },
            { id: 6, name: '数学七年级上册', publisher: '人民教育出版社', stage: '初中', grade: '初一', year: 2022, status: '现行', chapters: 4 },
            { id: 7, name: '数学七年级下册', publisher: '人民教育出版社', stage: '初中', grade: '初一', year: 2022, status: '现行', chapters: 5 },
            { id: 8, name: '数学六年级上册', publisher: '人民教育出版社', stage: '小学', grade: '六年级', year: 2021, status: '过渡', chapters: 7 },
            { id: 9, name: '数学六年级下册', publisher: '人民教育出版社', stage: '小学', grade: '六年级', year: 2021, status: '过渡', chapters: 6 },
            { id: 10, name: '数学必修一', publisher: '人民教育出版社', stage: '高中', grade: '高一', year: 2020, status: '停用', chapters: 5 },
        ];

        // 状态样式映射
        const statusStyles = {
            '现行': 'bg-green-100 text-green-800',
            '过渡': 'bg-yellow-100 text-yellow-800',
            '停用': 'bg-gray-100 text-gray-800'
        };

        // 渲染教材列表
        function renderTextbookList(data) {
            const listContainer = document.getElementById('textbookList');
            listContainer.innerHTML = '';
            
            data.forEach((item, index) => {
                const row = document.createElement('tr');
                row.className = 'hover:bg-gray-50 transition-smooth';
                row.innerHTML = `
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${index + 1}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${item.name}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.publisher}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.stage}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.grade}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.year}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${statusStyles[item.status]}">
                            ${item.status}
                        </span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.chapters}章</td>
                    <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                        <div class="flex justify-end gap-2">
                            <button class="text-primary hover:text-primary/80" title="编辑"><i class="fa fa-pencil"></i></button>
                            <button class="text-warning hover:text-warning/80" title="对比"><i class="fa fa-exchange"></i></button>
                            <button class="text-danger hover:text-danger/80" title="${item.status === '停用' ? '启用' : '停用'}">
                                <i class="fa ${item.status === '停用' ? 'fa-check-circle' : 'fa-ban'}"></i>
                            </button>
                        </div>
                    </td>
                `;
                listContainer.appendChild(row);
            });
        }

        // 初始化页面
        document.addEventListener('DOMContentLoaded', () => {
            renderTextbookList(textbookData);
            
            // 筛选功能
            document.getElementById('searchBtn').addEventListener('click', () => {
                const publisher = document.getElementById('publisherFilter').value;
                const stage = document.getElementById('stageFilter').value;
                const status = document.getElementById('statusFilter').value;
                
                // 筛选逻辑
                const filtered = textbookData.filter(item => {
                    return (publisher ? item.publisher === publisher : true) &&
                           (stage ? item.stage === stage : true) &&
                           (status ? item.status === status : true);
                });
                
                renderTextbookList(filtered);
                document.getElementById('showingRange').textContent = `1-${filtered.length}`;
                document.getElementById('totalCount').textContent = filtered.length;
            });

            // 弹窗控制
            const addBtn = document.getElementById('addBtn');
            const addModal = document.getElementById('addModal');
            const modalPanel = document.getElementById('modalPanel');
            const closeModal = document.getElementById('closeModal');
            const cancelBtn = document.getElementById('cancelBtn');

            // 显示弹窗
            addBtn.addEventListener('click', () => {
                addModal.classList.remove('hidden');
                setTimeout(() => {
                    modalPanel.classList.remove('scale-95', 'opacity-0');
                    modalPanel.classList.add('scale-100', 'opacity-100');
                }, 50);
            });

            // 关闭弹窗
            const hideModal = () => {
                modalPanel.classList.remove('scale-100', 'opacity-100');
                modalPanel.classList.add('scale-95', 'opacity-0');
                setTimeout(() => {
                    addModal.classList.add('hidden');
                }, 300);
            };

            closeModal.addEventListener('click', hideModal);
            cancelBtn.addEventListener('click', hideModal);
            addModal.addEventListener('click', (e) => {
                if (e.target === addModal) hideModal();
            });

            // 操作按钮事件
            document.querySelectorAll('#textbookList button').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const action = e.target.title;
                    const id = parseInt(e.target.closest('tr').querySelector('td:first-child').textContent);
                    alert(`${action} 教材 ID: ${id}`);
                });
            });
        });
    </script>
</body>
</html>
